//路由鉴权
//引入路由
import router from "./router";
// //引入插件
import nprogress from "nprogress";
//引入样式
import "nprogress/nprogress.css";
//引入大仓库
import pinia from "./store";
//引入用户仓库
import useUserStore from "./store/modules/User";
//获取用户仓库
let userStore = useUserStore(pinia);

//用户未登录可以访问的路由
let unLoginRoutes = [
  "/home",
  "/hospital/registration",
  "/hospital/detial",
  "/hospital/notice",
  "/hospital/Suspension",
  "/hospital/Select",
];
//前置路由守卫
router.beforeEach((to, from, next) => {
  //开启进度条
  nprogress.start();
  if (userStore.token) {
    next();
  }
  else {
    if(unLoginRoutes.includes(to.path)) {
        next();
    }else {
        userStore.dialogFormVisible = true;
        next({
            path:'/home',
            query:{
                redirect:to.fullPath
            }
        })
    }
  }
});
//后置路由守卫
router.afterEach((to, from) => {
  //关闭进度条
  nprogress.done();
});
